<?php
/**
 * Created by PhpStorm.
 * User: work
 * Date: 18-8-4
 * Time: 下午3:32
 */

namespace PddWechat\Models\Share\Dao;
use Dai\Framework\Base\BaseDao;
use Dai\Framework\Library\Log;
use PddWechat\Models\Share\DataObject\ShareQrDo;

/**
 * Class SharePosDao
 * @dataObject(\PddWechat\Models\Share\DataObject\ShareQrDo)
 * @package PddWechat\Models\Share\Dao
 */
class ShareQrDao extends BaseDao
{
    public function insert(ShareQrDo $shareQrDo)
    {
        $shareQrDo->id = $this->execute("share.invite.insert",$shareQrDo);
        return $shareQrDo;
    }


    public function selectMediaId($openId)
    {
        $param = [
            'openId' => $openId,
            'expireTime' => date('Y-m-d H:i:s', time()),
            'select' => '*'
        ];
        Log::info("selectMediaId param is ".var_export($param, true));
        $res = $this->execute("share.invite.select_valid_media", $param);
        if( count($res) > 0 ) {
            /** @var ShareQrDo $ret */
            $ret = $this->trimBase($res[0]);
            return $ret;
        }
        return null;
    }

}